package com.syedu.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * description：自定义老版日期工具类
 * @author Administrator
 * @date 2022/3/9 15:39
 */
public class DateUtil {
    /**
     * 根据指定的年月日来生成对应的日期
     */
    public static Date createDate(int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, day);
        return calendar.getTime();
    }

    /**
     * 格式化日期
     */
    public static String formatDate(Date date) {
        /*SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-ss HH:mm:ss");
        String result = simpleDateFormat.format(date);
        return result;*/
        return new SimpleDateFormat("yyyy-MM-ss HH:mm:ss").format(date);
    }

    public static String formatDate(Date date, String pattern) {
        return new SimpleDateFormat(pattern).format(date);
    }
}